home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light ROM 1
/
LIGHT-ROM 1 (Amiga Library Services)(1994).iso
/
ffdisks
/
d954.lha
/
SCAN8800
/
Example_in_C
/
SCAN8800_2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-27
|
8KB
|
279 lines
/**************************************************************************/
/*** Programmname: "SCAN8800_2.c" MIF-90 ***/
/*** Update : vom 17.02.91 ***/
/*** Beschreibung: Simple Steuerung des Empfängers FRG-8800 von YAESU ***/
/*** über das Interface MINIX MIF-90. ***/
/*** Autor : Rainer Redweik Kattowitzer Str. 7 D-3180 Wolfsburg 1***/
/*** Version : 1.0 ***/
/*** Computer : AMIGA 500 / 1000 / 2000 mit Kickstart 1.3 ***/
/*** Compiler : Aztec C V-5.0 with precompiled includefiles ***/
/*** : cc -ff -ps -so -wp -wu -hiInclude16.pre SCAN8800_1.c ***/
/*** : ln SCAN8800_1.o +q -lmf16 -lc16 ***/
/**************************************************************************/
#include <functions.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define WARTE 200L
#define UNIT_NUMBER 0L /* Multiple serial port */
#define SER_BUFFER_SIZE 5
/***************PROTOTYPES****************************************************/
void oeffnen(void);
void schliessen(void);
void Serial_Read(void);
void Serial_Write(void);
LONG Freq_to_Buffer(LONG);
void Set_Freq(LONG);
/***************STRUCTUREN****************************************************/
struct MsgPort *SerialMP = 0L; /* Für serial.device */
struct IOExtSer *SerialIO = 0L; /* Für serial.device */
/********************VARIABLE*************************************************/
TEXT SerialBuffer[SER_BUFFER_SIZE] = "";
LONG OpenDevErr = -1;
/********************FUNCTIONEN***********************************************/
void main(void)
{
LONG i;
oeffnen();
printf("\fBaud: %ld\n\n", SerialIO->io_Baud);
/* Fernb. ON */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x00,0x00);
Serial_Write();
Serial_Write(); /* Zur Sicherheit zweimal senden */
/* Netz ON */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0xfe,0x80);
Serial_Write();
/* AM wide */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x00,0x80);
Serial_Write();
printf("S 3 5 7 9 +20 +40 +60 dB\n");
for(i = 0L; i < 180L; i++)
Set_Freq(756000L);
printf("\n\n");
/* Netz OFF */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0xff,0x80);
Serial_Write();
/* Fernb. OFF */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x80,0x00);
Serial_Write();
schliessen();
}/* main() end*/
void oeffnen(void)
{
if(!(SerialMP = CreatePort(0,0)))
{
printf("CreatePort failed \n");
schliessen();
}
if(!(SerialIO = (struct IOExtSer *)CreateExtIO(SerialMP, sizeof(struct IOExtSer))))
{
printf("CreateExtIO failed \n");
schliessen();
}
SerialIO->io_SerFlags = SERF_SHARED | SERF_XDISABLED;
if((OpenDevErr = OpenDevice(SERIALNAME, UNIT_NUMBER, (struct IORequest *)SerialIO, 0L)) != 0L)
{
printf("Open-Device Error #%4lx IOERR_OPENFAIL: %ld\n", OpenDevErr, (LONG)IOERR_OPENFAIL);
schliessen();
}
SerialIO->IOSer.io_Command = CMD_RESET;
SendIO((struct IORequest *)SerialIO);
SerialIO->IOSer.io_Command = SDCMD_SETPARAMS;
SerialIO->io_Baud = 4800L;
SerialIO->io_ReadLen = SerialIO->io_WriteLen = 8;
SerialIO->io_StopBits = 2;
SendIO((struct IORequest *)SerialIO);
}/* oeffnen() end */
void schliessen(void)
{
if(SerialIO)
{
if(OpenDevErr == 0L)
{
AbortIO ((struct IORequest *)SerialIO);
WaitIO ((struct IORequest *)SerialIO);
CloseDevice((struct IORequest *)SerialIO);
}
DeleteExtIO((struct IORequest *)SerialIO);
}
if(SerialMP) DeletePort((struct MsgPort*)SerialMP);
exit(0);
}/* schliessen() end */
void Serial_Read(void)
{
LONG Temp;
ULONG WaitMask = SIGBREAKF_CTRL_C | 1L << SerialMP->mp_SigBit;
SerialIO->IOSer.io_Command = CMD_FLUSH;
DoIO((struct IORequest *)SerialIO);
/* Listing aus 'AMIGA ROMKERNEL Libraries&Devices Seite 863' */
SerialIO->IOSer.io_Command = CMD_READ;
SerialIO->IOSer.io_Length = SER_BUFFER_SIZE;
SerialIO->IOSer.io_Data = (APTR)&SerialBuffer[0];
SendIO((struct IORequest *)SerialIO);
while(1)
{
Temp = Wait(WaitMask);
if(SIGBREAKF_CTRL_C & Temp)
{
printf("Abbruch durch CTRL-C\n");
break;
}
if( CheckIO((struct IORequest *)SerialIO) )
{
WaitIO((struct IORequest *)SerialIO);
/* printf("%ld bytes received\n", SerialIO->IOSer.io_Actual);*/
break;
}
}
AbortIO((struct IORequest *)SerialIO);
WaitIO((struct IORequest *)SerialIO);
}/* Serial_Read() end */
void Serial_Write(void)
{
/*************************************************************************/
/* I am not glad about this part, but without this the programm dosn't */
/* work correct: only a few frequency-changes are possible. */
SerialIO->IOSer.io_Command = CMD_RESET;
DoIO((struct IORequest *)SerialIO);
SerialIO->IOSer.io_Command = SDCMD_SETPARAMS;
SerialIO->io_Baud = 4800L; /* Baud Rate */
SerialIO->io_ReadLen = SerialIO->io_WriteLen = 8; /* Bits */
SerialIO->io_StopBits = 2; /* Stop-Bits */
DoIO((struct IORequest *)SerialIO);
/*************************************************************************/
Delay(7L);
SerialIO->IOSer.io_Command = CMD_WRITE;
SerialIO->IOSer.io_Length = 5;
SerialIO->IOSer.io_Data = (APTR)SerialBuffer;
DoIO((struct IORequest *)SerialIO);
}/* Serial_Write() end */
LONG Freq_to_Buffer(LONG freq) /* Frequenz in die 4 Bytes umrechnen */
{
int b1, b2, b3, b4, b5 = 1;
int zehner, liByte, reByte = 1;
/* Frequency limits */
if (freq < 150000L) freq = 150000L;
else if(freq < 100000000L)
{
if(freq > 29999900L) freq = 29999900L;
}
else
{
if (freq < 144000000L) freq = 144000000L;
else if(freq > 146000000L) freq = 146000000L;
}
zehner = (int)(freq % 100L);
if (zehner < 13) {reByte = 1; freq = freq / 100L * 100L + 0L;}
else if(zehner < 38) {reByte = 2; freq = freq / 100L * 100L + 25L;}
else if(zehner < 68) {reByte = 4; freq = freq / 100L * 100L + 50L;}
else if(zehner < 88) {reByte = 8; freq = freq / 100L * 100L + 75L;}
else freq = freq / 100L * 100L + 100L;
liByte = (int)((freq % 1000L) / 100L); /* 100 Hz */
b1 = (liByte << 4) | reByte;
b2 = (int)((freq % 100000L) / 1000L);
b3 = (int)((freq % 10000000L) / 100000L);
b4 = (int)((freq % 1000000000L) / 10000000L);
b2 = ((b2 / 10) << 4) + b2 % 10; /* Umwandeln : Hex -> Dez */
b3 = ((b3 / 10) << 4) + b3 % 10;
b4 = ((b4 / 10) << 4) + b4 % 10;
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", b1, b2, b3, b4, b5);
return(freq);
}/* Freq_to_Buffer() end */
void Set_Freq(LONG freq) /* Frequenz einstellen und Werte auslesen */
{
float sm;
LONG frequenz;
int i, j;
frequenz = Freq_to_Buffer(freq);
Serial_Write();
Serial_Read();
/* Squelch erst beim 2ten Wert ermitteln, da der erste Wert unzuverlässig */
if(SerialBuffer[1] & 64 == 0)
{
printf("ZU\n");
return;
}
i = (SerialBuffer[1] & 63) / 2;
for(j = 0; j < i; j++)
printf("*");
for(j = 1; j <= 63 - i; j++)
printf(" ");
if((sm = (SerialBuffer[1] & 63) / 4.0F) > 9.0F)
printf(": %3d 9 +%2d\r", SerialBuffer[1] & 63, (int)(((sm - 9.0F) * 10.0F) + 2.5F) / 5 * 5);
else
printf(": %3d %2d \r", SerialBuffer[1] & 63, (int)sm);
fflush(stdout);
}/* Set_Freq() end */